#!/bin/bash

. /usr/lib/umm/umm_vars

# clean previos state
[ -f $UMM_FLAG ] && rm $UMM_FLAG

# check if UMM enabled
[  "$UMM" == "yes" ] || exit 0


if [ -f $UMM_DATA/UMM_ENFORCED ] ; then
    echo umm >$UMM_FLAG
    rm $UMM_DATA/UMM_ENFORCED
fi

# check if umm kernel parameter is present
for t in $(cat /proc/cmdline); do
    [ "$t" == "umm" ] && echo umm >$UMM_FLAG
done

# check if dirty rebout count is reached
UMM_DRC=$((UMM_DRC+1))
echo "UMM_DRC=$UMM_DRC">$UMM_DATA/UMM_DRC.var
[ ${UMM_DRC} -gt ${REBOOT_COUNT} ] && echo umm >$UMM_FLAG

initctl start umm-tr || true


if [ -f $UMM_FLAG ] ; then
    ${0}.${UMM_R}
    initctl start umm-run || true
fi


while [ -f $UMM_FLAG ] ; do sleep 1 ; done;

